package com.keyroy.game.puzzle_rpg.utils;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

public class StringUtil {
	public static final String SEPARATOR = ",";

	public static String intArray2str(List<Integer> is) {
		StringBuffer stringBuffer = new StringBuffer();
		for (int i = 0; i < is.size(); i++) {
			stringBuffer.append(is.get(i));
			if (i != is.size() - 1) {
				stringBuffer.append(SEPARATOR);
			}
		}
		return stringBuffer.toString();
	}

	public static void str2intArray(String str, List<Integer> out) {
		String[] strings = str.split(SEPARATOR);
		for (int i = 0; i < strings.length; i++) {
			try {
				out.add(Integer.parseInt(strings[i]));
			} catch (Exception e2) {
			}
		}
		if (out instanceof ArrayList<?>) {
			((ArrayList<?>) out).trimToSize();
		}
	}

	public static List<Integer> integers(Enumeration<Integer> enumeration) {
		List<Integer> list = new ArrayList<Integer>();
		while (enumeration.hasMoreElements()) {
			Integer integer = (Integer) enumeration.nextElement();
			list.add(integer);
		}

		return list;
	}

	public static final String stringOf(String string) {
		if (string != null) {
			return string;
		} else {
			return "";
		}
	}
}
